﻿var autoUplateTime = null;
$(document).ready(function () {
    var tp = 1;
    $.getScript("Scripts/jquery.signalR-1.2.1.min.js").done(function (script, textStatus) {
        $.getScript("signalr/hubs")
        .done(function (script, textStatus) {
            var TN = $.connection.TracNghiem;
            TN.client.error = function (mess) {
                alert(mess);
            }
            $.connection.hub.qs = "t=" + tp;
            $.connection.hub.start().done(function () {
                realtime = true;
                activeBox(1);
                var time = $('#timeExpired').val();
                var timeExpired = parseInt(time); //switch to second    
                $('.lb_count_down').countdown({ until: +timeExpired, format: 'MS', layout: '{mn} : {sn}', onExpiry: expired_time });
                autoUplateTime = setInterval(function () { TN.server.updateTime(code); }, 3000);
            }).fail(function (error) { alert("Không thể kết nối"); });

            $.connection.hub.error(function (error) {
                alert("Không thể kết nối");
            });
            
        });
    }).fail(function (jqxhr, settings, exception) {
        throw new Error("Error: Load resource.");
    });

});